home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / system-config-printer / troubleshoot / CheckSELinux.py < prev    next >
Encoding:
Python Source  |  2010-09-28  |  2.6 KB  |  79 lines

  1. #!/usr/bin/env python
  2.  
  3. ## Printing troubleshooter
  4.  
  5. ## Copyright (C) 2010 Red Hat, Inc.
  6. ## Copyright (C) 2010 Jiri Popelka <jpopelka@redhat.com>
  7.  
  8. ## This program is free software; you can redistribute it and/or modify
  9. ## it under the terms of the GNU General Public License as published by
  10. ## the Free Software Foundation; either version 2 of the License, or
  11. ## (at your option) any later version.
  12.  
  13. ## This program is distributed in the hope that it will be useful,
  14. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ## GNU General Public License for more details.
  17.  
  18. ## You should have received a copy of the GNU General Public License
  19. ## along with this program; if not, write to the Free Software
  20. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. import subprocess
  23. from base import *
  24. import os
  25. import shlex
  26. from timedops import TimedSubprocess
  27.  
  28. class CheckSELinux(Question):
  29.     def __init__ (self, troubleshooter):
  30.         Question.__init__ (self, troubleshooter, "Check SELinux contexts")
  31.         troubleshooter.new_page (gtk.Label (), self)
  32.  
  33.     def display (self):
  34.         self.answers = {}
  35.         #answers = self.troubleshooter.answers
  36.  
  37.         RESTORECON = "/sbin/restorecon"
  38.         if not os.access (RESTORECON, os.X_OK):
  39.             return False
  40.  
  41.         try:
  42.             import selinux
  43.         except ImportError:
  44.             return False
  45.         if not selinux.is_selinux_enabled():
  46.             return False
  47.  
  48.         paths = "/etc/cups/ /usr/lib/cups/ /usr/share/cups/"
  49.         null = file ("/dev/null", "r+")
  50.         parent = self.troubleshooter.get_window ()
  51.         contexts = {}
  52.         restorecon_args = "LC_ALL=C " + RESTORECON + " -nvR " + paths
  53.         try:
  54.             # Run restorecon -nvR
  55.             self.op = TimedSubprocess (parent=parent,
  56.                                        args=restorecon_args,
  57.                                        close_fds=True,
  58.                                        shell=True,
  59.                                        stdin=null,
  60.                                        stdout=subprocess.PIPE,
  61.                                        stderr=null)
  62.             (restorecon_stdout, restorecon_stderr, result) = self.op.run ()
  63.         except:
  64.             # Problem executing command.
  65.             return False
  66.         for line in restorecon_stdout:
  67.             l = shlex.split (line)
  68.             if (len (l) < 1):
  69.                 continue
  70.             contexts[l[2]] = l[4]
  71.         self.answers['selinux_contexts'] = contexts
  72.         return False
  73.  
  74.     def collect_answer (self):
  75.         return self.answers
  76.  
  77.     def cancel_operation (self):
  78.         self.op.cancel ()
  79.